package com.xiaoshuidi.cloud.framework.filings.core.enums;

import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 房屋朝向
 *
 * @Author Feng
 * @date 2023/5/5
 */
@Getter
@AllArgsConstructor
public enum HouseTowardEnum {
    SOUTH(1, "正南"),
    NORTH(2, "正北"),
    EAST(3, "正东"),
    WEST(4, "正西"),
    SOUTH_EAST(5, "东南"),
    NORTH_EAST(6, "东北"),
    SOUTH_WEST(7, "西南"),
    NORTH_WEST(8, "西北");


    private int code;
    private String name;

    public static Integer getCodeByName(String name) {
        if (StrUtil.isEmpty(name)) {
            return null;
        }
        Optional<HouseTowardEnum> find = Arrays.stream(HouseTowardEnum.values()).filter(s -> s.getName().equals(name)).findFirst();
        if (find.isPresent()) {
            return find.get().getCode();
        }
        return null;
    }
}
